<template>
	<view class="list">
		<block v-if="list.length>0">
			<view class="item" v-for="item in list" :key="item.id">
				<!-- <navigator :url="'/pages/source/detail?item='+ encodeURIComponent(JSON.stringify(item))"> -->
					<view class="content" >
						<rich-text class="rich_text" :nodes="item.content"></rich-text>
					</view>
				<!-- </navigator> -->
				<text class="time">{{item.addtime}}</text>
				<view class="delete" @click="deleteSource(item.id)"><image src="/static/delete.png" mode="widthFix" role="img"></image></view>
			</view>
		</block>
		<block v-else>
			<text class="none_data">没有数据</text>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				page: 0,
				isempty: false,
				isloading: false,
			};
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh(){
			this.page = 0;
			this.list = [];
			this.getList();
		},
		methods: {
			getList(){
				this.isloading = true;
				this.isempty = false;
				this.page++;
				this.$axios('Index/histryMsgs', 'POST', 'sale', {
					page: this.page
				}).then(res => {
					this.isloading = false;
					uni.stopPullDownRefresh()
					if (res.data.code == 200) {
						let data = res.data.data;
						if(data.length > 0) this.list = [...this.list, ...data];
						this.isempty = data.length <= 0;
					}
				})
			},
			deleteSource(id){
				var that = this;
				uni.showModal({//要写一个confirm函数，否则不能触发uni.openSetting函数
					//提示
					title: '确认删除',
					content: '是否要删除已发布的素材？',
					showCancel:true,
					cancelText:'取消',
					confirmText:'确认',
					success(res) {
						if(res.confirm){
							that.$axios('Index/delMsgs', 'POST', 'sale', {
								id: id
							}).then(res=>{
								if(res.data.code == 200){
									that.page = 0;
									that.list = [];
									that.getList();
									that.$api.msg('已删除');
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

	.list{
		padding: 20rpx;
		.item{
			margin-bottom: 20rpx;
			// &:first-child{
			// 	.content{
			// 		-webkit-line-clamp: unset;
			// 		overflow: auto;
			// 	}
			// }
			.content{
				font-weight: bolder;
				overflow: hidden;
				text-overflow: ellipsis;
				word-break: break-all;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				font-size: 26rpx;
				.rich_text{
					word-wrap: break-all;
					white-space: pre-line;
				}
				
			}
			.time{
				font-size: 22rpx;
				color: #999;
			}
			.delete{
				float: right;
				width: 32rpx;
				image{
					width: 100%;
				}
			}
		}
		.none_data{
			color: #bfb9b9;
			margin: 0 auto;
			font-size: 24rpx;
			display: block;
			text-align: center;
		}
	}
</style>
